#include "widget.h"
#include "ui_widget.h"
#include <QString>
int Widget::num = 1;
int Widget:: getscore = 0;

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->r->show();
    ui->w->show();
    connect(ui->btn,&QPushButton::clicked,this,&Widget::startTimer);
    connect(ui->btn,&QPushButton::clicked,this,&Widget::startgame);
    connect(ui->r,&QPushButton::clicked,this,&Widget::right);
    connect(ui->w,&QPushButton::clicked,this,&Widget::wrong);
}

Widget::~Widget()
{
    delete ui;
}
void Widget::startTimer()
{
   timer = new QTimer(this);
   connect(timer,&QTimer::timeout,this,&Widget::settimertext);
   timer->start(1000);
}

void Widget::settimertext()
{
    static int num = 300;
    num--;
    if(num <= 0)
    {
       timer->stop();
    }
    ui->time->setText(QString::number(num));
}


void Widget::startgame()
{
   ui->btn->hide();
   ui->r->show();
   ui->w->show();
   ui->label2->setText(arr[0]);
}

void Widget::right()
{
   ui->ti->setText(QString::number(num));
   if(num < 200)
   {
      ui->label2->setText(arr[num]);
   }
   else
   {
       num=0;
   }

   num++;
   getscore++;

   ui->score->setText(QString::number(getscore));
}
void Widget::wrong()
{
    ui->ti->setText(QString::number(num));
    if(num < 200)
    {
        ui->label2->setText(arr[num]);
    }
    else
    {
        num=0;
    }
    ui->score->setText(QString::number(getscore));

    num++;
}
